﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Data_Layer
{
    public sealed class Connection
    {
        private static Connection instance = null;
        private static SqlConnection con;

        private Connection()
        {            
            string str = ConfigurationManager.ConnectionStrings["PPSCon"].ConnectionString;
            //string str = "Server=localhost;Database=Internship;User Id=sa;Password=test;";
           

            try
            {
                System.Console.WriteLine("Opening Connection...");
                con = new SqlConnection(str);
                System.Console.WriteLine("Con Opened"+" ... " + con.Database +" ... " + con.DataSource);
            }
            catch (SqlException sqlException)
            {
                throw sqlException;
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message);
            }
        }
        public SqlConnection GetConnection()
        {
            return con;
        }
        public static Connection GetInstance()
        {
            if (instance == null)
            {
                instance = new Connection();
            }
            return instance;
        }
    }
}
